<?php
class ActivityAction extends BaseAction{
	public function addActivity(){
		$this->assign("position" ,"玩家互动、活动添加");
		if ( $this->isPost() ) {
			$data['title'] = addslashes(trim($_POST['title']));
			$data['content'] = trim($_POST['contents']);
			$data['times'] = addslashes(trim($_POST['time']));
			$result = M("activity")->data($data)->add();
			
			if ( $result ) {
				$this->assign("jumpUrl","__URL__/checkActivity");
				$this->assign("waitSecond",3);
				$this->success("玩家互动添加成功！！！");
			} else {
				$this->assign("jumpUrl","__URL__/addActivity");
				$this->assign("waitSecond",3);
				$this->error("玩家互动添加失败！！！");
			}
		} else {
			$this->display();
		}
	}
	
	public function checkActivity(){
		$this->assign("position" ,"玩家互动、活动查看");
		import("ORG.Util.Page");
		$count   = M("activity")->count();
		$Page    = new Page($count,6);
		$show    = $Page->show();
		$allActivity = M("activity")->order("times desc,id desc")->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign("activity",$allActivity);
		$this->assign("page",$show);
		$this->display();
	}
	
	public function delActivity(){
		if ( $_POST['id'] ) {
			$result = M("activity")->where("id=".$_POST['id'])->delete();
			if ( $result ){
				echo "success";
			}else {
				echo "failure";
			}
		} else {
			echo "failure";
		}
	}
	
	public function editActivity(){
		$this->assign("position" ,"玩家互动、活动修改");
		if ( $this->isPost() ) {
			$data['title'] = addslashes(trim($_POST['title']));
			$data['content'] = trim($_POST['contents']);
			$data['times'] = addslashes(trim($_POST['time']));
			$result = M("activity")->data($data)->where("id=".$_POST['id'])->save();
			if ( $result ){
				$this->assign("jumpUrl","__URL__/checkActivity");
				$this->assign("waitSecond",3);
				$this->success("活动修改成功！！！");
			} else {
				//$this->assign("jumpUrl","__URL__/checkNews");
				$this->assign("waitSecond",3);
				$this->error("活动失败成功！！！");
			}
				
		} else {
			if ( $_GET['id']){
				$activityinfo = M("activity")->where("id = ".$_GET['id'])->find();
				$this->assign("activityinfo" ,$activityinfo);
				//var_dump($activityinfo);die;
				$this->display();
			} else {
				$this->assign("waitSecond",3);
				$this->error("活动失败成功！！！");
			}
		}
	}
}